package com.stx.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author huzixuan
 * @date 2020-12-24 10:39
 */
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.获取前端参数
        String method = req.getParameter("method");
        if (method.equals("add")){
            System.out.println("123");
            req.getSession().setAttribute("msg","wowaawawaw");
        }


//        2.调用业务层
//        3.视图转发或重定向
        req.getRequestDispatcher("/index.jsp").forward(req,resp);//视图转发
//        resp.sendRedirect();//重定向

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
